package com.huawei.fastengine.fastview.download.download;

import java.util.HashMap;
import java.util.Map;

public class DownloadCallbackManager {
    private static DownloadCallbackManager instance = new DownloadCallbackManager();
    private int callbackId = 0;
    private Map<String, CallbackResult> callbacks = new HashMap();

    public interface CallbackResult {
        public static final int COMPLETED = 0;
        public static final int FAILURE = 2;
        public static final int USER_CANCEL = 1;

        void onCallback(int i);
    }

    private DownloadCallbackManager() {
    }

    public static DownloadCallbackManager getInstance() {
        return instance;
    }

    public synchronized String add(CallbackResult callbackResult) {
        this.callbackId++;
        this.callbacks.put(this.callbackId + "", callbackResult);
        return this.callbackId + "";
    }

    public synchronized void close() {
        this.callbacks.clear();
    }

    public synchronized void consume(String str, int i) {
        CallbackResult callbackResult = (CallbackResult) this.callbacks.remove(str);
        if (callbackResult != null) {
            callbackResult.onCallback(i);
        }
    }
}
